<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>千园千变，万班万课</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>
<body>
<div class="tpl-portlet-components">
    <div class="portlet-title">
        <ol class="am-breadcrumb">
            <li><a href="#" class="am-icon-home">首页</a></li>
            <li><a href="#">表单</a></li>
            <li class="am-active">Amaze UI 表单</li>
        </ol>
    </div>
    <div class="tpl-block ">
        <div class="am-g tpl-amazeui-form">
            <div class="am-u-sm-12">
                <form class="am-form am-form-horizontal">
                    <div class="am-form-group">
                        <label class="am-u-sm-2 am-form-label">地区</label>
                        <div class="am-u-sm-10 ">
                            <div class="line">
                                <select class="am-form-field" id="province" name="province_id"
                                        style="width: 150px;margin-right: 10px">
                                    <option value="0">请选择省</option>
                                </select>
                                <select class="am-form-field" id="city" name="city_id"
                                        style="width: 150px;margin-right: 10px">
                                    <option value="0">请选择市</option>
                                </select>
                                <select class="am-form-field" id="county" name="country_id" style="width: 150px">
                                    <option value="0">请选择区县</option>
                                </select>
                                <span class="tips"></span>
                            </div>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="username" class="am-u-sm-2 am-form-label">账号</label>
                        <div class="am-u-sm-10 line">
                            <input type="tel" id="username" name="username"
                                   class="verification[required,mobile]" data-info="账号"
                                   style="width: 300px" placeholder="账号(电话号)">
                            <span class="tips"> </span>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="name" class="am-u-sm-2 am-form-label">姓名</label>
                        <div class="am-u-sm-10 line">
                            <input type="text" class="verification[required]" data-info="姓名"
                                   id="name" name="name" style="width: 300px" placeholder="输入姓名">
                            <span class="tips"></span>
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="pwd" class="am-u-sm-2 am-form-label">密码</label>
                        <div class="am-u-sm-10">
                            <input type="password" id="pwd" name="pwd" style="width: 300px" placeholder="输入密码">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="two_pwd" class="am-u-sm-2 am-form-label">确认密码</label>
                        <div class="am-u-sm-10">
                            <input type="password" id="two_pwd" name="two_pwd" style="width: 300px"
                                   placeholder="输入确认密码">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="two_pwd" class="am-u-sm-2 am-form-label">机构名称</label>
                        <div class="am-u-sm-10">
                            <input type="text" id="institution_name"  class="verification[required]" data-info="机构名称" name="institution_name" style="width: 300px"
                                   placeholder="请输入机构名称">
                        </div>
                    </div>
                    <div class="am-form-group">
                        <label for="email" class="am-u-sm-2 am-form-label">邮箱</label>
                        <div class="am-u-sm-10">
                            <input type="email" id="email" name="email" style="width: 300px" placeholder="输入邮箱">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-2">
                            <button type="button" class="am-btn am-btn-primary" id="submitBtn">确定</button>
                            <button type="button" class="am-btn am-btn-default btn_back">返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/layer.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/md5.min.js"></script>
<script src="assets/js/verification.js"></script>
<script src="assets/js/request.js"></script>
<script src="assets/js/jquery.pagination.js"></script>
<script src="assets/js/jquery.serializejson.min.js"></script>
<script src="assets/js/jquery.params.js"></script>
<script src="assets/js/app.js"></script>
<script>
//获取地址
function getArea (id, elem, callback) {
  AjaxRequest({
    url: '/admin/city_list/',
    data: {id},
    succFun: function (res) {
      var data = res.data
      var html = '<option value="0">请选择省</option>'
      data.forEach(function (d) {
        html += ' <option value="' + d.id + '">' + d.fullName + '</option>'
      })
      $(elem).html(html)
      callback && callback()
    }
  })
}
getArea('0', '#province')
$('#province').change(function () {
  var id = $(this).val()
  getArea(id, '#city')
  $('#county').val('0')
})
$('#city').change(function () {
  var id = $(this).val()
  getArea(id, '#county')
})
var id = $.query.get("id").toString() || "undefined";
function getInfo () {
  if (id!=='undefined') {
    $('#two_pwd,#pwd').parents('.am-form-group').hide()
    AjaxRequest({
      url: '/admin/admin_info/',
      data: {admin_id: id},
      succFun: function (res) {
        console.log(res.data)
        var data = res.data
        getArea(data.province_id, '#city', function () {
          getArea(data.city_id, '#county',function () {
            $("form").initForm(res.data);

          })
        })
      }
    })
  }
}
getInfo()
$('#submitBtn').click(function (e) {
  e.preventDefault()
  if (Verification()) {
    var formData = $('form').serializeJSON()
    var url='/admin/agent_add/'
      if(id!=='undefined'){
        formData.admin_id = id
        url='/admin/agent_edit'
      }
    AjaxRequest({
      url,
      data: formData,
      succFun: function (res) {
        layer.msg(res.message, {icon: 1, time: 1000}, function () {
            window.location.href='admin_list.html'
        })
      }
    })
  }
})
</script>
</body>
</html>